<?php
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tucao/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/qq/inc.php");


//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	
	cgi::both($g_cgival["p"], "p", "");
	$g_cgival["p"] = intval($g_cgival["p"]);
	
	if($g_cgival["p"] < 1) $g_cgival["p"]=1;

	cgi::both($g_cgival["pcount"], "pcount", 20);
	$g_cgival["pcount"] = intval($g_cgival["pcount"]);
	
	
	cgi::both($g_cgival["uid"], "uid", "");
	$g_cgival["uid"] = intval($g_cgival["uid"]);
	
	cgi::both($g_cgival["show_type"], "show_type", "");
	$g_cgival["show_type"] = intval($g_cgival["show_type"]);
	
	cgi::both($g_cgival["order"], "order", "");
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	$pcount = $g_show["pcount"] = $g_cgival["pcount"];
	$p=$g_cgival["p"];
	//登录相关
	$user_info = new user_info();
	$is_login = $user_info->is_logined();
	
	$user_info = new user_info();
	$is_login = $user_info->is_logined();
	$g_show["p"] = $g_cgival["p"];
	$topic_id = $g_show["topic_id"] =  $g_cgival["topic_id"];
	
	if($is_login)
	{
		$user_detail_info = $user_info->get_cur_user_info();
	
		$uid = $user_detail_info["uid"];
		$user_nickname = $user_detail_info["user_nickname"];
		$g_show["is_logined"] = true;
		$g_show["current_user_info"] = $user_detail_info;
	}
	
	
	$uid = $g_cgival["uid"];

	var_dump($uid);
	exit;
	
	
	//类型1
	if($config["show_pubu"] == true)
	{
		$mod_mblog = new mod_mblog();
		$list = $mod_mblog->get_meinv_pubu_info($p,$pcount,$type="common",$topic_id);
		
		$g_show["list"] = $list["list"];
		$g_show["count"] = $list["count"];
	}
	else
	{
		$db_mblog_meinv_content = new db_mblog_meinv_content();
		$list = $db_mblog_meinv_content->get_mblog_pubu_list_by_topic($p,$pcount,$topic_id);
		$count = $db_mblog_meinv_content->get_mblog_pubu_count_by_topic($topic_id);
		$g_show["list"] = $list;
		$g_show["count"] = $count;
	}
	
	
	$db_mblog_meinv_topic = new db_mblog_meinv_topic();
	$meinv_topic_list = $db_mblog_meinv_topic->get_mblog_meinv_topic_list_order_by_like(1,5);
	$g_show["meinv_topic_list"] = $meinv_topic_list;
	
	$Pages = new Pages($g_show["count"],$g_cgival["p"],$g_cgival["pcount"]);
	$g_show["page_bar"] = $Pages->getLinks_static("/meinv/index_{$topic_id}_replacepage.html",8);
	
	
	
	$prev_page = ($p-1);
	if($prev_page > 0)
	{
		$g_show["prev"] = 	"/meinv/index_{$topic_id}_{$prev_page}.html";
	}
	
	$next_page = $p+1;
	$total_page = ceil($count/$pcount);
	if($next_page <= $total_page)
	{
		$g_show["next"] = 	"/meinv/index_{$topic_id}_{$next_page}.html";
		
	}
	
	
	//右侧推荐
		$db_gonglue = new db_gonglue();
		$gonglue_list1 = $db_gonglue->get_list_order_by_time(1,6,0,$config["current_site_id"],"",$item["create_time"]);
		$gonglue_list2 = $db_gonglue->get_list_order_by_time(1,6,1,$config["current_site_id"],"",$item["create_time"]);
		foreach($gonglue_list1 as $key => $value)
		{
			if($value["topic_id"])
			{
				$gonglue_list1[$key]["topic_name"] = $config["site_name"][$value["topic_id"]];
				$gonglue_list1[$key]["domain_url"] = "http://".$config["domain_url"][$value["topic_id"]];
			}
			$gonglue_list1[$key]["title_short"] = string_utf8::substr_utf8_cn_v2($gonglue_list1[$key]["title"],36);
		}
		
		foreach($gonglue_list2 as $key => $value)
		{
			if($value["topic_id"])
			{
				$gonglue_list2[$key]["topic_name"] = $config["site_name"][$value["topic_id"]];
				$gonglue_list2[$key]["domain_url"] = "http://".$config["domain_url"][$value["topic_id"]];
			}
			$gonglue_list2[$key]["title_short"] = string_utf8::substr_utf8_cn_v2($gonglue_list2[$key]["title"],36);
		}
			
		
		$g_show["gonglue_list1"] = $gonglue_list1;
		$g_show["gonglue_list2"] = $gonglue_list2;
		
		$db_mblog_meinv_content = new db_mblog_meinv_content();
		$meinv_tuijian_list = $db_mblog_meinv_content->get_mblog_meinv_list_by_tuijian(1,9,"",$item["create_time"]);
		foreach($meinv_tuijian_list as $key => $value)
		{
			$meinv_tuijian_list[$key]["pic_small"]  = str_replace("/bmiddle/","/thumb150/",$meinv_tuijian_list[$key]["pic"]);
		}
		
		$g_show["meinv_tuijian_list"] = $meinv_tuijian_list;
		
	
}

try {
	$g_show['error'] = 0;
	$g_show['errmsg'] = "";
	check_cgi_pro();
	get_data();
	
} catch (Exception $e) {
	$g_show['error'] = 1;
	$g_show['errmsg'] = $e->getMessage();
}

show_pro();


exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;

	$smarty = p_get_smarty();	
	$smarty->assign("g_show", $g_show);
	if (isset($_GET["debug"]))
	{
		print_r($g_show);
	}
	
	if($config["show_pubu"] == true)
	{
		$smarty->display("meinv/pubu.html");
	
	}
	else
	{
		$smarty->display("meinv/index.html");
	
	}
	unset($g_cgival);
	unset($g_pro);
	unset($g_show);
	unset($config);
	
}

